﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Mail;

namespace MailSender
{
    class Program
    {

        static void Main(string[] args)
        {
            int intnum;         //读取文件中有多少个数据
            StreamReader reader = new StreamReader("E://stu00.txt", System.Text.Encoding.Default);          //以中文编码格式打开文件
            string num = reader.ReadLine();         //逐行读取
            intnum = Convert.ToInt32(num);              //字符转换
            for (int i = 0; i < intnum; i++)
            {
                string message = reader.ReadLine();             //逐行读取
                string[] kk = message.Split(' ');               //根据空格切割
                string b = kk[1] + "同学（考号：" + kk[0] + "）参加2013年高等教育考试，被华软学院软件工程系" + kk[kk.Length - 2] + "专业方向录取，向您表示祝贺与欢迎！";
                System.Text.Encoding.UTF8.GetBytes(b);          //进行UTF8编码      
                System.Net.Mail.MailMessage mailit = new System.Net.Mail.MailMessage();
                mailit.To.Add(kk[kk.Length-3]);
                mailit.From = new MailAddress("1342830239@163.com", "华软", System.Text.Encoding.UTF8);//可以随便填写，除了最后一个编码方式
                mailit.Subject = "录取通知";                                //邮件标题   
                mailit.SubjectEncoding = System.Text.Encoding.UTF8;                //邮件标题编码   
                mailit.Body = b;                              //邮件内容   
                mailit.BodyEncoding = System.Text.Encoding.UTF8;                   //邮件内容编码   
                mailit.IsBodyHtml = false;                         //是否是HTML邮件   
                mailit.Priority = MailPriority.High;                       //邮件优先级   
                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("*********", "***********");         //GMail邮箱和密码   
                client.Port = 587;                          //Gmail使用的端口   
                client.Host = "smtp.gmail.com";                 //stmp
                client.EnableSsl = true;                    //经过ssl加密   
                object userState = mailit;
                try
                {
                    client.Send(mailit);
                }
                catch (System.Net.Mail.SmtpFailedRecipientException ex)
                {
                    Console.Write(ex.Message,"发送出错");
                }
            }
        }
    }              
    
}